import { SpriteFrameComponent } from "../../../engine/SpriteFrameComponent";
import ViewBase from "../../../engine/ViewBase";
import { ClubConfig } from "../../config/ClubConfig";
import { UserModel } from "../../model/UserModel";
import { UIHelper } from "../../util/UIHelper";


const { ccclass, property } = cc._decorator;

@ccclass
export default class ViewClubManager extends ViewBase {

    private tabIndex: number = 0;
    private shenpiNode: cc.Node
    private meberNode: cc.Node

    onEnable(): void {
        super.onEnable();
        this.shenpiNode = this.findChild(this.node, "shenpiNode")
        this.shenpiNode.active = false
        this.meberNode = this.findChild(this.node, "meberNode")
        this.meberNode.active = false
        // this.tabIndex = 0
        this.refreshTab()
    }

    private refreshTab() {
        for (let i = 0; i < 5; i++) {
            let btnTab: cc.Node = this.findChild(this.node, "btnTab" + i)
            if (i == 4) {
                btnTab.active = false
                // if (UserModel.instance.nowClub.actor == ClubConfig.Club_Actor_Type.owner) {
                //     btnTab.active = true
                // }
            }
            if (i == this.tabIndex) {
                btnTab.getComponent(cc.Sprite).spriteFrame = btnTab.getComponent(SpriteFrameComponent).spriteFrameList[1]
            } else {
                btnTab.getComponent(cc.Sprite).spriteFrame = btnTab.getComponent(SpriteFrameComponent).spriteFrameList[0]
            }
            UIHelper.onAddEvent(btnTab, () => {
                this.tabIndex = i;
                this.refreshTab();
            })
        }
        this.shenpiNode.active = false
        this.meberNode.active = false
        if (this.tabIndex == 0) {
            this.meberNode.active = true
        }
        else if (this.tabIndex == 1) {
            this.shenpiNode.active = true
        }
    }

}
